-include $(ROOTDIR)/config.mk

INCDIR += $(ROOTDIR)/include/server/ \
		  $(ROOTDIR)/package/debug/ \
		  $(ROOTDIR)/include/

INCLUDES = $(foreach INCTREE,$(INCDIR),$(addprefix -I, $(INCTREE)))


BIN = server
SOURCE += ./ \
		  ./device \
		  ./app \
		  ./../comm_protocol
OBJS = $(notdir $(patsubst %.c, %.o,$(foreach OBJTREE,$(SOURCE),$(wildcard $(OBJTREE)/*.c))))
#LIBS =

vpath %.c $(SOURCE)	

.PHONY: all install clean 

all: $(OBJS)
	$(CC) -o $(BIN) $(OBJS) $(INCLUDES) $(CFLAGS)

.c.o:
	$(CC) $(CFLAGS)  -c $< $(INCLUDES)

install:
	mkdir -p $(BUILDLDIR)/$(BIN)/bin/
	cp -f $(BIN) $(BUILDLDIR)/$(BIN)/bin
	mkdir -p $(BUILDLDIR)/$(BIN)/obj/
	cp -f $(OBJS) $(BUILDLDIR)/$(BIN)/obj/
	rm -rf $(BIN) *.asm *.o
	mkdir -p $(BUILDLDIR)/$(BIN)/include/
	cp -f $(ROOTDIR)/include/$(BIN)/*.h $(BUILDLDIR)/$(BIN)/include
	cp -f $(ROOTDIR)/include/*.h $(BUILDLDIR)/$(BIN)/include
	cp -f $(ROOTDIR)/package/debug/*.h $(BUILDLDIR)/$(BIN)/include
	cp -f $(ROOTDIR)/package/debug/core_dump/*.h $(BUILDLDIR)/$(BIN)/include
	cp -f $(ROOTDIR)/package/debug/memwatch/*.h $(BUILDLDIR)/$(BIN)/include

clean:
	rm -rf $(BIN)  *.o
